import { _decorator, Component, easing, Label, Node, Sprite, tween, Vec3 } from 'cc';
import { ResMgr } from '../Mgr/ResMgr';
import { AssetList } from '../Global';
const { ccclass, property } = _decorator;

@ccclass('Prompt_Cube')
/**
 * 提示方块
 */
export class Prompt_Cube extends Component {

    //
    @property(Sprite)
    private Cube: Sprite = null;

    //方块数量
    @property(Label)
    private CubeText: Label = null;

    private CubeIndex: number = 0;
    //方块数量
    public CubeNum: number = 0;

    public UpdateCubeInfor(_cubeindex: number, _cubenum: number) {
        console.log(_cubeindex, _cubenum, "更新样式")
        this.CubeIndex = _cubeindex;
        this.Cube.spriteFrame = ResMgr.Instance.SpriteFrames[AssetList.SpriteFrame.Ele + _cubeindex.toString()];
        this.CubeNum = _cubenum;
        this.CubeText.string = _cubenum.toString();

        tween(this.node).set({ scale: new Vec3(0.1, 0.1) }).to(0.2, { scale: new Vec3(1, 1) }, {
            easing: easing.backOut
        }).start();
        
    }

    /**
     * 减少方块
     */
    public RemoveCube(_cubeindex: number, _num: number) {
        if (this.CubeIndex != _cubeindex) return;
        this.CubeNum -= _num;
        if (this.CubeNum <= 0) this.CubeNum = 0;
        this.CubeText.string = this.CubeNum.toString();
    }

}


